/*
   Copyright 2010 Robert Roland

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/
package org.robertroland.touchshop.data

import android.database.sqlite.{SQLiteDatabase, SQLiteOpenHelper}
import android.util.Log
import android.content.{ContentValues, Context, ContentProvider}
import android.net.Uri
import android.database.Cursor

class DataProvider extends ContentProvider {

  private[this] val databaseName:String = "stores.db";
  private[this] val databaseVersion:Int = 1;

  private[this] val storesTable:String = "stores";

  class DatabaseHelper(context:Context) extends SQLiteOpenHelper(context, databaseName, null, databaseVersion) {
    def onCreate(database: SQLiteDatabase) = {
      Log.i("DatabaseHelper", "Creating new database")

      database.execSQL("CREATE TABLE " + storesTable + "(" +
        Store.STORE_ID_COL + " INTEGER PRIMARY KEY," +
        Store.STORE_NAME_COL + " TEXT" +
        ");")
    }

    def onUpgrade(database: SQLiteDatabase, oldVersion: Int, newVersion: Int) = {
      Log.w("DatabaseHelper", "Upgrading database...")
    }

    override def onOpen(db: SQLiteDatabase) = {

    }

    override def close = {
      
    }
  }
  
  override def update(uri: Uri, values: ContentValues, where: String, whereArgs: Array[String]): Int = 0

  override def delete(uri: Uri, where: String, whereArgs: Array[String]): Int = 0
  
  override def insert(uri: Uri, values: ContentValues): Uri = null
  
  override def getType(uri: Uri): String = ""
	  
  override def query(uri: Uri, projection: Array[String], selection: String, selectionArgs: Array[String], sortOrder: String): Cursor = null
  
  override def onCreate: Boolean = true
}